//
//  WDPersonalSettingHeaderCell.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/8/17.
//

#import "WDPersonalSettingHeaderCell.h"

@interface WDPersonalSettingHeaderCell ()

@property (nonatomic, strong) TYZCommonCellModel *model;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIImageView *headerImgView;

@property (nonatomic, strong) UIImageView *thanImgView;

@property (nonatomic, strong) CALayer *bottomLine;


- (void)initWithTitleLabel;

- (void)initWithHeaderImgView;

- (void)initWithThanImgView;


@end

@implementation WDPersonalSettingHeaderCell

- (void)initWithVarCell {
    [super initWithVarCell];
    
}

- (void)initWithSubViewCell {
    [super initWithSubViewCell];
    
    
    CGRect frame = CGRectMake(kRealValue(20), kWDPersonalSettingHeaderCellHeight - 1, self.width - kRealValue(20) * 2, 1);
    self.bottomLine = [CALayer drawLine:self frame:frame lineColor:[UIColor colorWithHexString:@"#f1f0f0"]];
}

- (void)initWithTitleLabel {
    if (!_titleLabel) {
        NSString *str = @"交付中心大家";
        float width = [str widthForFont:[UIFont systemFontOfSize:16 weight:UIFontWeightMedium]];
        CGRect frame = CGRectMake(kRealValue(20), (self.height - 30) * 0.5, width, 30);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:14 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
        }];
    }
    if (self.model) {
        self.titleLabel.text = objectNull(self.model.title);
    }
}

- (void)initWithHeaderImgView {
    if (!_headerImgView) {
        CGRect frame = CGRectMake(self.titleLabel.right, (kWDPersonalSettingHeaderCellHeight - 60) * 0.5, 60, 60);
        _headerImgView = [[UIImageView alloc] initWithFrame:frame];
        _headerImgView.layer.cornerRadius = frame.size.height * 0.5;
        _headerImgView.layer.masksToBounds = YES;
        _headerImgView.backgroundColor = [UIColor orangeColor];
        [self.contentView addSubview:_headerImgView];
        
        _headerImgView.userInteractionEnabled = YES;
        @weakify(self);
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            @strongify(self);
            [self actionWithHeader];
        }];
        [self.headerImgView addGestureRecognizer:tap];
    }
    if (self.model) {
        [self.headerImgView sd_setImageWithURL:[NSURL URLWithString:self.model.url] placeholderImage:nil];
    }
}

- (void)initWithThanImgView {
    if (!_thanImgView) {
        UIImage *image = [UIImage imageNamed:@"ic_than_eee"];
        CGRect frame = CGRectMake(self.width - 16 - image.size.width, (self.height - image.size.height) * 0.5, image.size.width, image.size.height);
        _thanImgView = [[UIImageView alloc] initWithFrame:frame];
        _thanImgView.image = image;
        [self addSubview:_thanImgView];
    }
}

/// 点击头像，更换头像
- (void)actionWithHeader {
    if (self.touchHeaderBlock) {
        self.touchHeaderBlock();
    }
}

- (void)updateCellData:(id)cellEntity {
    self.model = cellEntity;
    
    [self initWithTitleLabel];

    [self initWithHeaderImgView];

    [self initWithThanImgView];
}

@end
